package com.hns.phone.safety.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.DriverInterfaceAnnotation;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.aop.sedate.SedateAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.master.entity.CommDrvSctBhvInfoEntity;
import com.hns.can.master.service.TendencyChartsDataTools;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.phone.safety.vo.DrivingBehaviorParamVo;
import com.hns.phone.safety.vo.DrivingBehaviorTypeRanking;
import com.hns.tool.pub.PubUtil;

@Service
public class PhoneDrivingBehaviorService extends CommonService {
	
	@Autowired
    private FillCodeDscValue codeDscValue;
	
	@Autowired
	private TendencyChartsDataTools tendencyChartsDataTools;
	
	/**
     * 翻译解释基础名称
     * @param list
     * @author:zhangzq
     * @email:
     */
    private void fillCodeDscValue(List list) throws Exception{
        Map<String,String> map = new HashMap<String,String>();
        map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo1 = new FillParamsVo("lineId", map);
//        codeDscValue.fillInfoValue(list, vo, GlobalConst.CACHE_KEY_BASE_LINE_INFO);
        map = new HashMap<String,String>();
        map.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo2 = new FillParamsVo("organId", map);
//        codeDscValue.fillInfoValue(list, vo, GlobalConst.CACHE_KEY_BASE_ORGAN);
        map = new HashMap<String,String>();
        map.put("drvName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo3 = new FillParamsVo("drvId", map);
//        codeDscValue.fillInfoValue(list, vo, GlobalConst.CACHE_KEY_BASE_DRV_INFO);
        map = new HashMap<String,String>();
        map.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo4 = new FillParamsVo("carId", map);
        codeDscValue.fillInfoValue(list, new String[]{GlobalConst.CACHE_KEY_BASE_LINE_INFO, 
        		GlobalConst.CACHE_KEY_BASE_ORGAN, GlobalConst.CACHE_KEY_BASE_DRV_INFO, 
        		GlobalConst.CACHE_KEY_BASE_CAR_INFO}, vo1, vo2, vo3, vo4);
        map.clear();
        map.put("drvSctBhv", "DRV00000");
        codeDscValue.fillCodeDscValue(list, map);
    }
	
	/**
	 * @author:jjb
	 * @email:375324644@qq.com
	 * @创建日期:2014-7-10
	 * @功能说明：驾驶员行为分页数据
	 */
	@LeftOrgAnnotation()
	@Transactional
	@DriverInterfaceAnnotation()
	@SedateAnnotation()
	public Pagination getDrivingBehavior(DrivingBehaviorParamVo entity,
			HttpServletRequest request) throws Exception{
		Pagination page = this.myBatisPage(
				"phoneDrivingBehavior.getDrivingBehaviorListCount",
				"phoneDrivingBehavior.getDrivingBehaviorList", entity, 
				CommDrvSctBhvInfoEntity.class);
		// 公式注入
		List list=page.getData();
		fillCodeDscValue(list);
		page.setData(list);
		return page;
	}

	
	public List getUnfaseBhvTrend(Map<String, Object> map, String dateType) throws Exception{
		Class<?> clazz = Class.forName("com.hns.phone.safety.vo.HarmfulTendencyVo");
		List<T> list = null;
		try{
			List tmpList = null;
			if(PubUtil.isNotEmpty(map.get("lineId"))){
				tmpList  = tendencyChartsDataTools.fillMultiTendencyData(this.sqlMapDao.selectList("phoneDrivingBehavior.ubsafeBhvTendency", map), dateType);
				list = PubUtil.convertListMapToObject(tmpList, clazz);
			}else{
				//vo.setIdxTypeArr();
				map.put("idxTypeArr", new String[]{"041101","041102","041103","041104","041105","041106","041107","041108","041109","041110","041111","041112","041113","041114","041199"});
				tmpList  = tendencyChartsDataTools.fillMultiTendencyData(this.sqlMapDao.selectList("phoneDrivingBehavior.carUbsafeBhvTendency", map), dateType);
				list = PubUtil.convertListMapToObject(tmpList, clazz);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
	}

	
	public Pagination getUnfaseBhvTypeRank(DrivingBehaviorParamVo param) {
		Pagination page = this.myBatisPage("phoneDrivingBehavior.getUnfaseBhvTypeRankCount", "phoneDrivingBehavior.getUnfaseBhvTypeRank", param, DrivingBehaviorTypeRanking.class);
		return page;
	}

	
}
